package main

import (
	"fmt"
	"time"
)

func main() {
	ch := make(chan string)
	//ch := make(chan string, 5)	//带缓冲的通道
	go Push(ch)
	//go Pop(ch)
	time.Sleep(10 * time.Second)
}

func Push(ch chan string) {
	for i := 0; i < 10; i++ {
		data := fmt.Sprintf("Hello_%d", i)
		ch <- data	//向通道中写入数据
		fmt.Println("put data " + data + " to channel success")
		time.Sleep(200 * time.Millisecond)
	}
}

func Pop(ch chan string) {
	for  {
		data := <- ch	//读取通道中的数据
		fmt.Printf("get data from channel. %s\n", data)
	}
}